<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="../node_modules/vue/dist/vue.js"></script>

    <div id="app">
        <ul>
            <li v-for="user in users">
                {{user.name}} -- {{user.gender | genderFilter}} -- {{user.age}} -- {{user.gender | gFilter}}
            </li>
        </ul>
    </div>

    <script>
        // 定义全局过滤器
        Vue.filter("gFilter", function (val) {
            if (val == 0) {
                return '女'
            } else {
                return '男'
            }
        })

        new Vue({
            el: '#app',
            data: {
                users: [{ name: '刘亦菲', gender: 0, age: 18 },
                { name: '古力娜扎', gender: 0, age: 24 },
                { name: '董卿', gender: 0, age: 24 },
                { name: '微雨', gender: 1, age: 22 }]
            },
            filters: {
                // 定义局部过滤器
                genderFilter(val) {
                    if (val == 0) {
                        return '女'
                    } else {
                        return '男'
                    }
                }
            }
        })
    </script>
</body>

</html>